package com.rongcheng.frc.androidlib.net.requestCallback;

import android.util.Log;

import com.alibaba.fastjson.JSON;
import com.rongcheng.frc.androidlib.net.interf.YXBaseCallbackInterface;
import com.rongcheng.frc.androidlib.net.mock.YXResponse;
import com.zhy.http.okhttp.callback.StringCallback;

import okhttp3.Call;

/**
 * Created by FengRongCheng on 2016/6/18 18:36.
 * powered by yanxiu.com
 * 研修项目的基本回调抽象类   里面将okhttp_utils的StringCallback进行封装
 */
public abstract class YXBaseCallBack extends StringCallback implements YXBaseCallbackInterface {

    @Override
    public void onError(Call call, Exception e, int id) {
        onFail(e.getMessage(), false);
    }

    @Override
    public void onResponse(String responseStr, int id) {
        YXResponse response = JSON.parseObject(responseStr, YXResponse.class);
        String responseString = response.getData();
        if ("0".equals(response.getCode())) {
            Log.e("frc", "code::" + response.getCode() + "  msg::" + response.getDesc());
            onSuccess(responseString, false);
        } else {
            Log.e("frc", "code::" + response.getCode() + "  msg::" + response.getDesc());
            onFail(response.getDesc(), false);

        }


    }

    @Override
    public void inProgress(float progress, long total, int id) {
        onProgress(progress, total);
    }

    /**
     * 接口调用进度  不是每个接口都要有
     *
     * @param progress
     * @param total
     */
    @Override
    public void onProgress(float progress, long total) {
        Log.e("frc", "onProgesss:;" + progress / total + "%");
    }

    /**
     * 关于Cookie过期的设置
     */
    @Override
    public void onCookieExpired() {

    }
}
